var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
  data: {
    datalist: [],
		pagenum:1,
		keyword:'',
  },
  _onLoad: function () {
    var that = this
		that.setData({ pagenum: 1, datalist: [], $nomoreData: false});
    $.get('scoreshop/index', {}, function (res) {
      that.setData(res);
    });
		wx.setNavigationBarTitle({
			title: (that.data.textset['积分'] || '积分')+'商城'
		});
    //that.getDataList();
  },
  getDataList: function () {
    var that = this
    var pagenum = that.data.pagenum
    var keyword = that.data.keyword
		that.setData({loaddingmore:true})
    $.post('scoreshop/index', { pagenum: pagenum, id: that.data.id,keyword:keyword}, function (res) {
			that.setData({loaddingmore:false})
      var data = res.datalist
      if (pagenum == 1) {
        that.setData({ datalist: data });
        if (data.length == 0) {
          $.showEmpty('暂无相关数据！');
        }
      } else {
        if (data.length == 0) {
          that.setData({ $nomoreData: true });
        } else {
          var datalist = that.data.datalist
          var newdata = datalist.concat(data)
          that.setData({ datalist: newdata });
        }
      }
      that.setData({
        sclist: data
      });
    },false);
  },
  onReachBottom: function () {
    if (!this.data.$dataEmpty.visible && !this.data.$nomoreData) {
      this.setData({ pagenum: this.data.pagenum + 1 })
      this.getDataList();
    }
  },
	search:function(e){
		var keyword = e.detail.value;
		var that = this
		that.setData({ pagenum: 1, datalist: [], $nomoreData: false,keyword:keyword});
		that.getDataList();
	}
}))